/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef RUNTIME_KB_OP_HASH_H_
#define RUNTIME_KB_OP_HASH_H_
#include <cstddef>
#include <cstdint>
#include <functional>
namespace RuntimeKb {
namespace {
constexpr size_t kGoldenRatio = 0x9e3779b9;
constexpr uint32_t kSixBitShift = 6U;
constexpr uint32_t kTwoBitShift = 2U;
constexpr uint32_t kEightBitShift = 8U;
constexpr uint32_t kSixtennBitShift = 16U;
constexpr uint32_t kHashSeed = 271828U;
}  // namespace

template <typename T>
struct Hash {
  size_t operator()(const T& tt) const {
    return std::hash<T>()(tt);
  }
};

template <typename T>
inline void HashCombine(const T& val, uint32_t& out) {
  out ^= Hash<T>()(val) + kGoldenRatio + (out << kSixBitShift) + (out >> kTwoBitShift);
}

uint32_t CommonHash(const void* src, uint32_t len, uint32_t seed = kHashSeed);
}  // namespace RuntimeKb
#endif
